package com.deyang.mycommon.adapter;


import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.deyang.mycommon.R;
import com.deyang.mycommon.entity.SelectImageItem;
import com.deyang.mycommon.util.ImageUtil;
import com.deyang.mycommon.util.ViewUtil;

import java.util.List;


/**
 * @author 王德阳
 * @data 创建时间: 2017/10/31 0031
 * @Description 草图 listview item 编辑
 */
public class SelectImagesAdapter extends BaseQuickAdapter<SelectImageItem, BaseViewHolder> {


    public SelectImagesAdapter(@Nullable List<SelectImageItem> data) {
        super(R.layout.item_card_image_info, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SelectImageItem item) {
        RelativeLayout rl_cardImage = helper.getView(R.id.rl_cardImage);
        ViewUtil.setHeightForWidth(rl_cardImage);
        ImageView iv_cardImage = helper.getView(R.id.iv_cardImage);
        LinearLayout ll_delete = helper.getView(R.id.ll_delete);
        ImageView iv_add = helper.getView(R.id.iv_add);

        if (item.isCanAdd()) {
            iv_add.setVisibility(View.VISIBLE);
            iv_cardImage.setVisibility(View.GONE);
            ll_delete.setVisibility(View.INVISIBLE);
        } else {

            iv_add.setVisibility(View.GONE);
            iv_cardImage.setVisibility(View.VISIBLE);
            ll_delete.setVisibility(View.VISIBLE);

            ImageUtil.loadImage(mContext, iv_cardImage, item.getSketchPath(), R.drawable.load_fail);
        }

        helper.addOnClickListener(R.id.ll_delete);
    }
}
